package com.fit.pages.registration;

import java.util.Calendar;
import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.UserAccess;
import com.fit.dao.registration.LicencePlateDAO;
import com.fit.dao.registration.RegistrationDAO;
import com.fit.dao.vehicle.VehicleDAO;
import com.fit.entities.LicencePlate;
import com.fit.entities.Payment;
import com.fit.entities.Registration;
import com.fit.entities.Vehicle;
import com.fit.pages.Confirmation;

@UserAccess
@AdminAccess
public class Details {

	@InjectPage
	private ManageRegistrations manage;
	
	@Property
	@Persist
	private LicencePlate licencePlate;
	
	@Inject
	private LicencePlateDAO licencePlateDAO;
	
	@Property
	@Persist
	private List<Registration> registrations;
	
	@Property
	private Registration registrationRow;;
	
	@Inject
	private RegistrationDAO registrationDAO;
	
	@Persist
	@Property
	private String date;
	
	@Persist
	@Property
	private String expDate;
	
	@Persist
	@Property
	private String firstRegDate;
		

	Object onActivate(String licencePlateNo) {
		licencePlate = licencePlateDAO.findByLicencePlateNo(licencePlateNo);
		registrations = registrationDAO.findByLicencePlateNo(licencePlate);
		return null;
	}
	
	@OnEvent(component = "deleteLink")
	Object onDeleteLink(String id) {
		manage.setConfirmation("");
		manage.setError("");
		Long l = new Long(id);
		try {
			registrationDAO.delete(l);
			manage.setConfirmation("Registration successfully deleted.");
			return manage;
		} catch (Exception e) {
			manage.setError("Error deleting registration. ");
			return manage;
		}
	}

}
